<template>
  <div style="display: inline-block;">
    <label style="width: 100px">登录方式</label>
    <el-select v-model="loginPage" size="mini" style="width: 100px" @change="handleChange">
      <el-option v-for="item in options.LOGIN_PAGE.list" :key="item.key" :label="item.label"
                 :value="item.value"></el-option>
    </el-select>
  </div>
</template>

<script>
import LStorage from "@/cache/localStorage";
import {hasToken} from "@/permission/permission";
import utils from "@/common/utils";
import {LOGIN_PAGE} from "@/common/dict";
import store from "@/store/store";

export default {
  name: "logInSwitcher",
  props: {},
  data() {
    return {
      loginPage: LStorage.get(LStorage.keys.LOGIN_PAGE),
      options: {
        LOGIN_PAGE
      }
    }
  },
  methods: {
    handleChange(loginPage) {
      LStorage.set(LStorage.keys.LOGIN_PAGE, loginPage)
      this.redirect(loginPage)
    },
    // 路由跳转
    redirect(loginPage) {
      switch (loginPage) {
        case LOGIN_PAGE.enum.PC.value:
          if (hasToken()) {
            store.dispatch('permission/logout')
          } else {
            window.location.href = '/'
          }
          break
        case LOGIN_PAGE.enum.ONE_MACHINE.value:
          if (hasToken()) {
            store.dispatch('permission/logout')
          } else {
            window.location.href = '/'
          }
          break
      }
    }
  },
  created() {
  }
}
</script>

<style scoped>

</style>
